package com.gsnd.gsnd22estore.web.controller;


import com.gsnd.gsnd22estore.result.Result;
import com.gsnd.gsnd22estore.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    BookService bookService;

    @GetMapping("/showBooks")
    public Result showBooks(){
        return Result.success(bookService.getBookList());
    }

    @GetMapping("/findByCategory/{id}")
    public Result findByCategory(@PathVariable Integer id)
    {
        return Result.success(bookService.getBookListByCategory(id));
    }

    @GetMapping("/searchBook")
    public Result searchBook(String query ){
        return Result.success(bookService.getBookListByCondition(query));
    }

    @GetMapping("/{id}")
    public Result findBookId(@PathVariable Integer id)
    {
        return Result.success(bookService.getBookById(id));
    }

}
